<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

if (!($partner_id = $route->getAdminId()))
	goToPage("/admin/partners");

$errors = array();

if ($route->POST('action') == 'edit')
{
	$name = UV::readMQ($route->POST('name'));
	$e_mail = UV::readMQ($route->POST('e_mail'));
	$site_name = UV::readMQ($route->POST('site_name'));
	$url = UV::readMQ($route->POST('url'));
	$city = UV::readInt($route->POST('city'));
	$power = $route->POST('power') ? "1" : "0";
	$show_main = $route->POST('show_main') ? "1" : "0";
	
	$query = "update `business_partners`
		set
			`name` = '{$name}',
			`e-mail`='{$e_mail}',
			`site_name`='{$site_name}',
			`url`='{$url}',
			`city_id`='{$city}',
			`power`='{$power}',
			`show_main`='{$show_main}'
		 where
		 	`id` = '$partner_id' limit 1";
	$db->sendQuery($query);
}

$bp = $db->getRow("select * from `business_partners` where `id` = '$partner_id' limit 1");
if ($bp == null)
	goToPage("/admin/partners");

loadPage("head.php");
?>

<h1>Редактирование сайта</h1><br /><?php
	if (count($errors) > 0)
		echo "<p class='fail'>".implode("<br />",$errors)."<br /><br /></p>";
	elseif ($route->POST('action') == 'edit')
		echo "<p class='success'>Успешно отредактировано<br /><br /></p>";
?>
<form method='POST'>
	<input type='hidden' name='action' value='edit' />
	<table cellpadding='3' cellspacing='5'>
		<tr>
			<td width='170px'><label for="name">Имя контакта</label></td>
			<td width='300px'><input type='text' id="name" name='name' value='<?php echo $bp['name']; ?>' /></td>
		</tr>
		<tr>
			<td><label for="e_mail">E-mail</label></td>
			<td><input type='text' id="e_mail" name='e_mail' value='<?php echo $bp['e-mail']; ?>' /></td>
		</tr>
		<tr>
			<td><label for="site_name">Название</label></td>
			<td><input type='text' id="site_name" name='site_name' value='<?php echo $bp['site_name']; ?>' /></td>
		</tr>
		<tr>
			<td><label for="url">URL</label></td>
			<td><input type='text' id="url" name='url' value='<?php echo $bp['url']; ?>' /></td>
		</tr>
		<tr>
			<td><label for="city">Город</label></td>
			<td>
				<select name="city" id="city" class="double_short">
					<option value="0">Вся Россия</option>
					<option disabled="disabled">———————————</option>
					<?php
					$cities_list = $db->getTable("select `city_id`,`name` from `city` order by `name`");
					echo select_create($cities_list,"city_id","name",$bp['city_id']);
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label for="power">Включен</label></td>
			<td><input type='checkbox' id="power" name='power' <?php if ($bp["power"]) echo "checked='checked'"; ?> /></td>
		</tr>
		<tr>
			<td><label for="show_main">На главной</label></td>
			<td><input type='checkbox' id="show_main" name='show_main' <?php if ($bp["show_main"]) echo "checked='checked'"; ?> /></td>
		</tr>
		<tr>
			<td colspan='2' align='right'><input type='submit' value='Редактировать' /></td>
		</tr>
	</table>
</form>

<?php loadPage("footer.php"); ?>